package nc.ui.wds.xstj;

import nc.itf.scm.excel.ExcelImportProcess;
import nc.ui.pub.ClientEnvironment;
import nc.ui.pub.beans.UIRefPane;
import nc.ui.pub.bill.BillEditEvent;
import nc.ui.pub.bill.BillItem;
import nc.ui.trade.manage.ManageEventHandler;
import nc.vo.pub.CircularlyAccessibleValueObject;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.trade.field.BillField;

public class XstjUI extends AbstractXstjUI implements ExcelImportProcess {
	protected ManageEventHandler createEventHandler() {
		return new MyEventHandler(this, getUIControl());
	}

	public void setBodySpecialData(CircularlyAccessibleValueObject[] vos)
			throws Exception {
	}

	protected void setHeadSpecialData(CircularlyAccessibleValueObject vo,
			int intRow) throws Exception {
	}

	protected void setTotalHeadSpecialData(CircularlyAccessibleValueObject[] vos)
			throws Exception {
	}

	protected void initSelfData() {
		getBillCardPanel().setAutoExecHeadEditFormula(true);
		UIRefPane custname = (UIRefPane) getBillCardPanel().getBodyItem(
				"custname").getComponent();
		custname.setReturnCode(false);

		UIRefPane refInv = (UIRefPane) getBillCardPanel()
				.getBodyItem("invcode").getComponent();
		refInv.setMultiSelectedEnabled(true);
		refInv.setTreeGridNodeMultiSelected(true);

		String[] items_numbers = { "nnumber" };
		for (String item_number : items_numbers) {
			getBillCardPanel().getBodyItem(item_number).setDecimalDigits(8);
			getBillListPanel().getBodyItem(item_number).setDecimalDigits(8);
		}
		String[] items_Prices = { "nprice" };
		for (String item_number : items_Prices) {
			getBillCardPanel().getBodyItem(item_number).setDecimalDigits(4);
			getBillListPanel().getBodyItem(item_number).setDecimalDigits(4);
		}
	}

	public void setDefaultData() throws Exception {
		BillField fileDef = BillField.getInstance();
		String billtype = getUIControl().getBillType();
		String pkCorp = ClientEnvironment.getInstance().getCorporation()
				.getPrimaryKey();

		String[] itemkeys = { fileDef.getField_Corp(),
				fileDef.getField_Operator(), fileDef.getField_Billtype(),
				fileDef.getField_BillStatus(), "dbilldate", "tmaketime" };
		Object[] values = { pkCorp,
				ClientEnvironment.getInstance().getUser().getPrimaryKey(),
				billtype, new Integer(8).toString(),
				ClientEnvironment.getInstance().getDate(),
				new UFDateTime(System.currentTimeMillis()).toString() };

		for (int i = 0; i < itemkeys.length; i++) {
			BillItem item = null;
			item = getBillCardPanel().getHeadItem(itemkeys[i]);
			if (item == null)
				item = getBillCardPanel().getTailItem(itemkeys[i]);
			if (item != null)
				item.setValue(values[i]);
		}
	}

	public void afterEdit(BillEditEvent e) {
		((MyEventHandler) getManageEventHandler()).afterEdit(e);
	}

	public void processAfterImport(
			CircularlyAccessibleValueObject[] importbodyVO,
			CircularlyAccessibleValueObject headVO) throws Exception {
		((MyEventHandler) getManageEventHandler()).processAfterImport(
				importbodyVO, headVO);
	}

	public void processBeforeImport(String keyWord) throws Exception {
		((MyEventHandler) getManageEventHandler()).processBeforeImport(keyWord);
	}

	@Override
	protected void initPrivateButton() {
		ImportERPBtn2VO btn1 = new ImportERPBtn2VO();
		addPrivateButton(btn1.getButtonVO());
		super.initPrivateButton();
	}
}